package com.example.garbage.controller;

import com.example.garbage.pojo.Process;
import com.example.garbage.pojo.RespBean;
import com.example.garbage.pojo.Station;
import com.example.garbage.service.ProcessService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author Shunrai
 * @create 2024/3/22 16:58
 * @Version 1.0
 * @Description
 */
@RestController
@RequestMapping("/process")
@ApiResponse(responseCode = "404", description = "查询失败")
@ApiResponse(responseCode = "200", description = "查询成功")
@Tag(name = "厨余垃圾处理点")
public class ProcessController {
    @Autowired
    private ProcessService processService;

    @GetMapping("/getAll")
    public RespBean<Process> getAllProcess(){
        List<Process> list = processService.list();
        return RespBean.success("查询成功",list);
    }

    @GetMapping("/getMany/{ids}")
    @Operation(summary = "根据id获取垃圾处理站")
    public RespBean<Process> getDepotByIds(@PathVariable("ids")@Parameter(description = ",分割") String ids){
        String[] split = ids.split(",");
        List<Integer> idList = new ArrayList<>();
        for (String str : split) {
            int number = Integer.parseInt(str);
            idList.add(number);
        }
        List<Process> manyByIds = processService.getManyByIds(idList);
        return RespBean.success("查询成功",manyByIds);
    }

}
